package cn.webrx;

import java.io.File;
import java.util.concurrent.TimeUnit;

public class File2 {
    public static void main(String[] args) {
        File f = new File("st.txt");
        System.out.println(f.exists());//true
        System.out.println(f.isFile());//true,不存在也是false
        System.out.println(f.length());//获取文件的字节数
        System.out.println(f.listFiles());//此方法主要是目录对象
        System.out.println(f.isDirectory());
        System.out.printf("%tF %<tT", f.lastModified());
        System.out.println();

        //获取文件绝对路径
        System.out.println(f.getAbsoluteFile());
        System.out.println(f.getAbsolutePath());
        System.out.println(f.getPath());//st.txt
        System.out.println(f.getName());//st.txt

        //删除文件
        File f2 = new File("user.txt");
        try {
            System.out.println(f2.createNewFile());
        } catch (Exception e) {
            e.printStackTrace();
        }

        /*
        if (f2.exists() && f2.isFile()) {
            System.out.println(f2.delete());
        }*/

        //System.out.println(f2.delete());
        //f2.deleteOnExit(); main方法结束时执行没有返回值。
        //f2.deleteOnExit();

        try{
            TimeUnit.SECONDS.sleep(15);
        }catch(Exception e){
            e.printStackTrace();
        }

        System.exit(1);
        System.out.println("hello aaa");
        System.out.println("hello aaa");
        System.out.println("hello aaa");
        System.out.println("hello aaa");

    }
}
